// 通知相关类型定义

export interface Notification {
  id: number // 后端是Long类型
  userId: number // 后端是Long类型
  taskId?: string
  taskType?: string
  title: string
  content: string
  status: 0 | 1 // 后端是Integer类型：0-未读，1-已读
  type: 0 | 1 | 2 // 后端是Integer类型：0-系统通知，1-任务通知，2-其他
  createTime: string // 后端是LocalDateTime，前端接收为字符串
  updateTime?: string // 后端是LocalDateTime，前端接收为字符串
  extraData?: string // 后端是String类型，可能是JSON字符串
}

// 后端返回的IPage<Notification>结构
export interface NotificationPageResponse {
  code: number
  message: string
  data: {
    records: Notification[]
    total: number
    size: number
    current: number
    pages: number
  }
}

// 保持向后兼容
export interface NotificationListResponse {
  code: number
  message: string
  data: {
    list: Notification[]
    total: number
    page: number
    size: number
  }
}

export interface NotificationCountResponse {
  code: number
  message: string
  data: number // 后端直接返回数字，不是对象
}

export interface NotificationResponse {
  code: number
  message: string
  data: Notification
}

export interface CommonResponse {
  code: number
  message: string
}

// 便于前端使用的枚举
export const NotificationStatus = {
  UNREAD: 0,
  READ: 1
} as const

export const NotificationType = {
  SYSTEM: 0,
  TASK: 1,
  OTHER: 2
} as const

// 将后端状态转换为前端显示文本
export const getStatusText = (status: number): string => {
  switch (status) {
    case NotificationStatus.UNREAD:
      return '未读'
    case NotificationStatus.READ:
      return '已读'
    default:
      return '未知'
  }
}

// 将后端类型转换为前端显示文本
export const getTypeText = (type: number): string => {
  switch (type) {
    case NotificationType.SYSTEM:
      return '系统通知'
    case NotificationType.TASK:
      return '任务通知'
    case NotificationType.OTHER:
      return '其他'
    default:
      return '未知'
  }
}